﻿using UnityEngine;
using Zero;

/// <summary>
/// 元素反应：绽放
/// </summary>
public class ElementBloom : IElementReaction
{
    private readonly IElementHolder _holder;

    public ElementBloom(IElementHolder holder)
    {
        _holder = holder;
    }

    public void Reaction(TriggerElementData triggerElementData)
    {
        if (triggerElementData.ElementType == ElementType.Water)
        {
            var grassAura = _holder.GetGeneralElementAura(ElementType.Grass);
            if (grassAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 0.5f;
                triggerElementData.Gauge -= grassAura.Gauge * 2f;
                grassAura.UseGauge(cost);
                Create();
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "绽放");
                return;
            }
        }

        if (triggerElementData.ElementType == ElementType.Grass)
        {
            var waterAura = _holder.GetGeneralElementAura(ElementType.Water);
            if (waterAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 2f;
                triggerElementData.Gauge -= waterAura.Gauge * 0.5f;
                waterAura.UseGauge(cost);
                Create();
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "绽放");
            }
        }
    }

    private void Create()
    {
        Debug.Log("创建种子");
    }
}